package com.example.demo.model.controller;


import com.example.demo.common.QueryParameter;
import com.example.demo.common.TestSql;
import com.example.demo.model.component.GPSSComponent;
import com.example.demo.model.component.MySQLComponent;
import com.example.demo.model.component.GreenPlumComponent;
import com.example.demo.model.component.OracleComponent;
import com.example.demo.student.entity.Student;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author yuanzheng
 * @since 2021-05-28
 */
@RestController
@RequestMapping("/student")
public class DemoController {

    @Autowired
    private MySQLComponent mySQLComponent;

    @Autowired
    private OracleComponent oracleComponent;

    @Autowired
    private GreenPlumComponent greenPlumComponent;

    @Autowired
    private GPSSComponent gpssComponent;

//    @PostMapping("/list")
//    public List<Student> getStudentList() {
//        return mySQLComponent.getStudents();
//    }
//
//    @PostMapping("/save")
//    public int saveStudent(Student student) {
//        return mySQLComponent.saveStudents(student);
//    }

    /**
     * 测试GPSS入库
     */
    @PostMapping("/testGPSSInsert")
    @ApiOperation(value = "测试GPSS入库", tags = {"其他接口"})
    public String testGPSSInsert() {

        return gpssComponent.testGPSSInsert();
    }

    /**
     * 单SQL执行
     */
    @PostMapping("/testSql")
    @ApiOperation(value = "单SQL执行", tags = {"其他接口"})
    public String testSql(TestSql testSql) {
        Integer type = testSql.getType();
        if (type == 0) {
            return mySQLComponent.testSql(testSql);
        }
        return greenPlumComponent.testSql(testSql);
    }

    /**
     * GreenPlum相关操作
     *
     * @return 步骤消耗时间
     */
    @PostMapping("/gpTestQuery")
    @ApiOperation(value = "GP-分布表", tags = {"分页查询"})
    public String gpTestQuery(QueryParameter queryParameter) {
        String tableName = "yuan_test";
        queryParameter.setTableName(tableName);
        return greenPlumComponent.testQuery(queryParameter);
    }

    @PostMapping("/gpTestReplicatedQuery")
    @ApiOperation(value = "GP-Replicated表", tags = {"分页查询"})
    public String gpTestReplicatedQuery(QueryParameter queryParameter) {
        String tableName = "yuan_test_replicated";
        queryParameter.setTableName(tableName);
        return greenPlumComponent.testQuery(queryParameter);
    }

    @PostMapping("/gpTestInsert")
    @ApiOperation(value = "GP-分布表", tags = {"入库"})
    public String gpTestInsert() {
        String tableName = "yuan_test";
        return greenPlumComponent.testInsert(tableName);
    }

    @PostMapping("/gpTestReplicatedInsert")
    @ApiOperation(value = "GP-Replicated表", tags = {"入库"})
    public String gpTestReplicatedInsert() {
        String tableName = "yuan_test_replicated";
        return greenPlumComponent.testInsert(tableName);
    }

    @PostMapping("/gpTestInsertByBatch")
    @ApiOperation(value = "GP-分布表", tags = {"入库-批量"})
    public String gpTestInsertByBatch() {
        String tableName = "yuan_test";
        return greenPlumComponent.testInsertByBatch(tableName);
    }

    @PostMapping("/gpTestReplicatedInsertByBatch")
    @ApiOperation(value = "GP-Replicated表", tags = {"入库-批量"})
    public String gpTestReplicatedInsertByBatch() {
        String tableName = "yuan_test_replicated";
        return greenPlumComponent.testInsertByBatch(tableName);
    }

    @PostMapping("/gpTestDelete")
    @ApiOperation(value = "GP-分布表", tags = {"删除"})
    public String gpTestDelete() {
        String tableName = "yuan_test";
        return greenPlumComponent.testDelete(tableName);
    }

    @PostMapping("/gpTestReplicatedDelete")
    @ApiOperation(value = "GP-Replicated表", tags = {"删除"})
    public String gpTestReplicatedDelete() {
        String tableName = "yuan_test_replicated";
        return greenPlumComponent.testDelete(tableName);
    }

    @PostMapping("/gpTestDeleteByBatch")
    @ApiOperation(value = "GP-分布表", tags = {"删除-批量"})
    public String gpTestDeleteByBatch() {
        String tableName = "yuan_test";
        return greenPlumComponent.testDeleteByBatch(tableName);
    }

    @PostMapping("/gpTestReplicatedDeleteByBatch")
    @ApiOperation(value = "GP-Replicated表", tags = {"删除-批量"})
    public String gpTestReplicatedDeleteByBatch() {
        String tableName = "yuan_test_replicated";
        return greenPlumComponent.testDeleteByBatch(tableName);
    }

    @PostMapping("/gpTestUpdate")
    @ApiOperation(value = "GP-分布表", tags = {"更新"})
    public String gpTestUpdate() {
        String tableName = "yuan_test";
        return greenPlumComponent.testUpdate(tableName);
    }

    @PostMapping("/gpTestReplicatedUpdate")
    @ApiOperation(value = "GP-Replicated表", tags = {"更新"})
    public String gpTestReplicatedUpdate() {
        String tableName = "yuan_test_replicated";
        return greenPlumComponent.testUpdate(tableName);
    }

    @PostMapping("/gpTestUpdateByBatch")
    @ApiOperation(value = "GP-分布表", tags = {"更新-批量"})
    public String gpTestUpdateByBatch() {
        String tableName = "yuan_test";
        return greenPlumComponent.testUpdateByBatch(tableName);
    }

    @PostMapping("/gpTestReplicatedUpdateByBatch")
    @ApiOperation(value = "GP-Replicated表", tags = {"更新-批量"})
    public String gpTestReplicatedUpdateByBatch() {
        String tableName = "yuan_test_replicated";
        return greenPlumComponent.testUpdateByBatch(tableName);
    }

    /**
     * MySQL相关操作
     *
     * @return 步骤消耗时间
     */
    @PostMapping("/mysqlTestQuery")
    @ApiOperation(value = "MySQL", tags = {"分页查询"})
    public String mysqlTestQuery(QueryParameter queryParameter) {
        String tableName = "yuan_test";
        queryParameter.setTableName(tableName);
        return mySQLComponent.testQuery(queryParameter);
    }

    @PostMapping("/mysqlTestInsert")
    @ApiOperation(value = "MySQL", tags = {"入库"})
    public String msTestInsert() {
        return mySQLComponent.testInsert();
    }

    @PostMapping("/mysqlTestInsertByBatch")
    @ApiOperation(value = "MySQL", tags = {"入库-批量"})
    public String msTestInsertByBatch() {
        return mySQLComponent.testInsertByBatch();
    }

    @PostMapping("/mysqlTestDelete")
    @ApiOperation(value = "MySQL", tags = {"删除"})
    public String msTestDelete() {
        return mySQLComponent.testDelete();
    }

    @PostMapping("/mysqlTestDeleteByBatch")
    @ApiOperation(value = "MySQL", tags = {"删除-批量"})
    public String msTestDeleteByBatch() {
        return mySQLComponent.testDeleteByBatch();
    }

    @PostMapping("/mysqlTestUpdate")
    @ApiOperation(value = "MySQL", tags = {"更新"})
    public String msTestUpdate() {
        return mySQLComponent.testUpdate();
    }

    @PostMapping("/mysqlTestUpdateByBatch")
    @ApiOperation(value = "MySQL", tags = {"更新-批量"})
    public String msTestUpdateByBatch() {
        return mySQLComponent.testUpdateByBatch();
    }

    /**
     * 全流程测试（新增+查询+修改+删除）
     *
     * @return 各个流程时间消耗
     */
    @PostMapping("/gpTest")
    @ApiOperation(value = "GP-分布表", tags = {"全流程"})
    public String gpTest() {
        String tableName = "yuan_test";
        String testInsert = greenPlumComponent.testInsert(tableName);
//        String testQuery = greenPlumComponent.testQuery(tableName);
        String testUpdate = greenPlumComponent.testUpdate(tableName);
        String testDelete = greenPlumComponent.testDelete(tableName);
        return testInsert + testUpdate + testDelete;
    }

    @PostMapping("/gpTestReplicated")
    @ApiOperation(value = "GP-Replicated表", tags = {"全流程"})
    public String gpTestReplicated() {
        String tableName = "yuan_test_replicated";
        String testInsert = greenPlumComponent.testInsert(tableName);
//        String testQuery = greenPlumComponent.testQuery(tableName);
        String testUpdate = greenPlumComponent.testUpdate(tableName);
        String testDelete = greenPlumComponent.testDelete(tableName);
        return testInsert + testUpdate + testDelete;
    }

    @PostMapping("/mysqlTest")
    @ApiOperation(value = "MySQL", tags = {"全流程"})
    public String mysqlTest() {
        String tableName = "yuan_test";
        String testInsert = mySQLComponent.testInsert();
//        String testQuery = mySQLComponent.testQuery(tableName);
        String testUpdate = mySQLComponent.testUpdate();
        String testDelete = mySQLComponent.testDelete();
        return testInsert + testUpdate + testDelete;
    }

    @PostMapping("/gpTestByBatch")
    @ApiOperation(value = "GP-分布表", tags = {"全流程-批量"})
    public String gpTestByBatch() {
        String tableName = "yuan_test";
        String testInsert = greenPlumComponent.testInsertByBatch(tableName);
//        String testQuery = greenPlumComponent.testQuery(tableName);
        String testQuery = "大数据量不进行查询";
        String testUpdate = greenPlumComponent.testUpdateByBatch(tableName);
        String testDelete = greenPlumComponent.testDeleteByBatch(tableName);
        return testInsert + testQuery + testUpdate + testDelete;
    }

    @PostMapping("/gpTestReplicatedByBatch")
    @ApiOperation(value = "GP-Replicated表", tags = {"全流程-批量"})
    public String gpTestReplicatedByBatch() {
        String tableName = "yuan_test_replicated";
        String testInsert = greenPlumComponent.testInsertByBatch(tableName);
//        String testQuery = greenPlumComponent.testQuery(tableName);
        String testQuery = "大数据量不进行查询";
        String testUpdate = greenPlumComponent.testUpdateByBatch(tableName);
        String testDelete = greenPlumComponent.testDeleteByBatch(tableName);
        return testInsert + testQuery + testUpdate + testDelete;
    }

    @PostMapping("/mysqlTestByBatch")
    @ApiOperation(value = "MySQL", tags = {"全流程-批量"})
    public String mysqlTestByBatch() {
        String tableName = "yuan_test";
        String testInsert = mySQLComponent.testInsertByBatch();
//        String testQuery = mySQLComponent.testQuery(tableName);
        String testQuery = "大数据量不进行查询";
        String testUpdate = mySQLComponent.testUpdateByBatch();
        String testDelete = mySQLComponent.testDeleteByBatch();
        return testInsert + testQuery + testUpdate + testDelete;
    }

}

